<?php
require_once 'include/base.php';
#require_once 'libs/top/Taoapi.php';
require_once 'include/topwrap.php';
require_once 'include/global.func.php';
$smarty = new TopSmartyBase();

$top_config = Taoapi_Config::Init();
$top_config->setCharset('UTF-8');

$taoapi = new TopWrap(false,false);
$cat_items = $taoapi->getItemCats();
$tmpcats   = $cat_items['item_cats']['item_cat'];
$count     = count($tmpcats);
for( $i=0; $i<$count; $i++ )
{
	$tmpcats[$i]['cat_url'] = url('list',array('catid'=>$tmpcats[$i]['cid']));
}
$smarty->getSmarty()->assign('item_cats',$tmpcats);
unset($tmpcats);
unset($cat_items);

$iid = $_GET['iid'];
if(!$iid)
{
	die('Not Right Itemid');
}

$item = $taoapi->getItemByIID($iid);
if(isset($item['taobaoke_item_details']['taobaoke_item_detail']['item']['cid'])) 
{
	$smarty->getSmarty()->assign('catnav',gen_nav($item['taobaoke_item_details']['taobaoke_item_detail']['item']['cid'], &$taoapi));
}
$cat = $taoapi->getItemCat($item['taobaoke_item_details']['taobaoke_item_detail']['item']['cid']);

//var_dump($item);
if( is_array($item['taobaoke_item_details']['taobaoke_item_detail']['click_url']) || 
	empty($item['taobaoke_item_details']['taobaoke_item_detail']['click_url']))
{
	$item['taobaoke_item_details']['taobaoke_item_detail']['click_url'] = 'find.php?type=item&title='.$item['taobaoke_item_details']['taobaoke_item_detail']['item']['title'];
}
if( is_array($item['taobaoke_item_details']['taobaoke_item_detail']['shop_click_url']) || 
	empty($item['taobaoke_item_details']['taobaoke_item_detail']['shop_click_url']))
{
	$item['taobaoke_item_details']['taobaoke_item_detail']['shop_click_url'] = 'find.php?type=item&title='.$item['taobaoke_item_details']['taobaoke_item_detail']['item']['title'];
}
$smarty->getSmarty()->assign('item',$item['taobaoke_item_details']['taobaoke_item_detail']);
$smarty->getSmarty()->assign('title',$item['taobaoke_item_details']['taobaoke_item_detail']['item']['title']);
$smarty->getSmarty()->assign('keywords',$item['taobaoke_item_details']['taobaoke_item_detail']['item']['title']);
$sort = $item['taobaoke_item_details']['taobaoke_item_detail']['item'];
$smarty->getSmarty()->assign('description','类别:'.$cat['item_cats']['item_cat']['name'].',卖家:'.$sort['nick'].',价格:'.$sort['price'].'元');
$smarty->getSmarty()->display('item.tpl');